<template>
  <div>
    <base-list ref="baselist"
               :condition="condition"
               :datas.sync="cargoData"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="验收单号"
                          class="search-width6">
              <auto-search-cargo-type-name @selectName="v=>condition['search_LIKE_cargoTypeName']=v"></auto-search-cargo-type-name>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车船号"
                          class="search-width6">
              <auto-search-cargo-type-name @selectName="v=>condition['search_LIKE_cargoTypeName']=v"></auto-search-cargo-type-name>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="货主"
                          class="search-width6">
              <auto-search-name v-model="condition['search_EQ_cargoOwnerId']"
                                placeholder="请选择"
                                @selectId="v=>condition['search_EQ_cargoOwnerId']=v"
                                :name="form.cargoOwnerName"></auto-search-name>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="品名"
                          class="search-width6">
              <auto-search-name v-model="condition['search_EQ_cargoOwnerId']"
                                placeholder="请选择"
                                @selectId="v=>condition['search_EQ_cargoOwnerId']=v"
                                :name="form.cargoOwnerName"></auto-search-name>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="内转车号"
                          class="search-width6">
              <el-select v-model="condition['search_EQ_contractStatus']"
                         placeholder="请选择"
                         clearable
                         filterable>
                <el-option v-for="[key, val] in _dictContractStatus"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="作业点"
                          class="search-width6">
              <auto-search-name v-model="condition['search_EQ_cargoOwnerId']"
                                placeholder="请选择"
                                @selectId="v=>condition['search_EQ_cargoOwnerId']=v"
                                :name="form.cargoOwnerName"></auto-search-name>
            </el-form-item>
          </el-col>
          <el-col :span="5"
                  class="search-width8">
            <el-form-item label="创建时间">
              <el-date-picker style="width:150px;"
                              v-model="condition['search_GTE_createDateTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker> 至
              <el-date-picker style="width:150px;"
                              v-model="condition['search_LTE_createDateTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button type="primary"
                       icon="el-icon-search"
                       @click="loadData">查 询</el-button>
            <el-button formVisible="true"
                       icon="el-icon-refresh"
                       @click="resuleBtn('aList')">
              重置
            </el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                :data="cargoData"
                border
                stripe
                max-height="550">
        <el-table-column type="expand"
                         width="60">
          <template slot-scope="props">
            <el-form label-position="left"
                     inline
                     class="demo-table-expand">
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="上账重量">
                  <span>{{ props.row.arriveWeight}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="验收数量">
                  <span>{{ props.row.checkAcceptCount}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="验收人">
                  <span>{{ props.row.checkAcceptMan}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="验收时间">
                  <span>{{ props.row.checkAcceptTime}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="复核人">
                  <span>{{ props.row.aduitMan}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="复核时间">
                  <span>{{ props.row.aduitTime}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="转为存单人">
                  <span>{{ props.row.stockBillMan }}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="转为存单时间">
                  <span>{{ props.row.stockBillTime }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="上账人">
                  <span>{{ props.row.inAccountMan }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="上账时间">
                  <span>{{ props.row.inAccountTime }}</span>
                </el-form-item>
              </el-col>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column type="index"
                         label="序号"
                         width="50"
                         align="center"></el-table-column>
        <el-table-column prop="checkAcceptNo"
                         label="验收单号"
                         width="100"></el-table-column>
        <el-table-column prop="stockBillNo"
                         label="存单号"
                         width="150"></el-table-column>
        <el-table-column prop="accountPageNo"
                         label="账页号"
                         width="100"></el-table-column>
        <el-table-column prop="auditStatus"
                         label="状态"
                         width="100">
          <template slot-scope="scope">
            {{ scope.row.auditStatus | _filterAdjustStatus}}
          </template>
        </el-table-column>
        <el-table-column prop="cargoOwnerName"
                         label="货主"
                         width="120"></el-table-column>
        <el-table-column prop="transhipNo"
                         label="车船号"
                         width="100"></el-table-column>
        <el-table-column prop="cargoName"
                         label="品名"
                         width="80"></el-table-column>
        <el-table-column prop="material"
                         label="材质"
                         width="120"></el-table-column>
        <el-table-column prop="normStr"
                         label="规格"
                         width="100"></el-table-column>
        <el-table-column prop="madeBy"
                         label="生产厂家"
                         width="120"></el-table-column>
        <el-table-column prop="measureWay"
                         label="计量方式"
                         width="120">
          <template slot-scope="scope">
            {{ scope.row.measureWay | _filterMeterStyle}}
          </template>
        </el-table-column>
        <el-table-column prop="manageWay"
                         label="管理方式"
                         width="80">
          <template slot-scope="scope">
            {{ scope.row.manageWay | _filterManagement}}
          </template>
        </el-table-column>
        <el-table-column prop="carNo"
                         label="内转车号"
                         width="80"></el-table-column>
        <el-table-column prop="jobPointName"
                         label="作业点"
                         width="80"></el-table-column>
        <el-table-column prop="checkAcceptWeight"
                         label="验收重量"
                         width="80"></el-table-column>
        <el-table-column prop="checkAcceptNum"
                         label="验收件数"
                         width="80"></el-table-column>
        <el-table-column label="操作"
                         align="center"
                         width="60"
                         fixed="right">
          <template slot-scope="scope">
            <el-button type="text"
                       size="small"
                       @click="handleDialogForm(scope.row)">查看</el-button>
            <!-- <el-button type="text"
                       size="small"
                       @click="handleLinkDialogForm(scope.row)">查看实物信息</el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </base-list>
    <div style="text-align:center">
      <el-button plain
                 type="info"
                 plain
                 @click="handleRouterPush({path: '/goods/enter',name: '入库作业平台'})">返回</el-button>
    </div>
    <view-in-check-detail-form ref="viewInCheckDetailForm"></view-in-check-detail-form>
  </div>
</template>

<script>
import { getAcceptanceInList } from '@/api/enter/acceptanceIn' //表格列表
import autoSearchCargoTypeName from '@/components/autocomplete/autoSearchCargoTypeName'
import autoSearchName from '@/components/autocomplete/autoSearchName'
import viewInCheckDetailForm from './viewInCheckDetailForm'

export default {
  name: 'receiveNote',
  components: {
    autoSearchCargoTypeName,
    autoSearchName,
    viewInCheckDetailForm
  },
  data() {
    return {
      form: this.clearForm(),
      condition: {}, // 查询条件
      pageSearch: getAcceptanceInList, // 分页查询api接口
      cargoData: [], // table数组
      multipleSelection: [],
      total: 0
    }
  },
  mounted() {
    getAcceptanceInList().then(res => {
      console.log('00', res.data.aaData)
    })
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    clearForm() {
      return {}
    },
    loadData() {
      this.$refs.baselist.loadData()
    },
    //查看
    handleDialogForm(item) {
      this.$refs.viewInCheckDetailForm.form = item
      this.$refs.viewInCheckDetailForm.dialogForm = true
    },
    //查看实物信息
    handleLinkDialogForm(item) {
      this.$refs.linkObjectInfoForm.form = item
      this.$refs.linkObjectInfoForm.dialogForm = true
    },
    //删除
    handleRemove(item) {
      this.$confirm(`是否删除该数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteCargo(item.id).then(res => {
            this.$message({
              type: 'success',
              message: `删除成功!`
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    //获取批量删除的数据
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    //批量删除
    handleRemoveAll(item) {
      this.$confirm(`是否删除选中的数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          item.forEach(i => {
            deleteCargo(i.id).then(res => {
              this.$message({
                type: 'success',
                message: `删除成功!`
              })
              this.loadData()
            })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    //合计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (
          column.property === 'totalReleasedWeight' ||
          column.property === 'totalPledgedWeight' ||
          column.property === 'totalControlWeight' ||
          column.property === 'totalUseWeight'
        ) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          sums[index]
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    //重置
    resuleBtn(aList) {
      this.$refs[aList].resetFields()
      this.condition = this.clearForm()
    },
    //返回
    handleRouterPush(val) {
      this.$store.commit('ADD_CACHED_VIEWS', val)
      this.$router.push(val.path)
    }
  }
}
</script>

<style scoped>
.content {
  /* background: #ffffcf; */
}
.tagName {
  color: blue;
  cursor: pointer;
}
</style>
